<template>
  <div>
    <link
      rel="stylesheet"
      href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css"
    >
    <script
      charset="utf-8"
      type="text/javascript"
      src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js"
    />
    <!-- 定义播放器dom -->
    <div id="J_prismPlayer" class="prism-player" />
  </div>
</template>

<script>
import vodApi from '@/api/vod'
export default {
  data: function() {},
  asyncData({ params, error }) {
    return vodApi.getAuth(params.id).then((response) => {
      return {
        vid: params.id,
        auth: response.data.data.auth
      }
    })
  },

  mounted() {
    new Aliplayer(
      {
        id: 'J_prismPlayer',
        vid: this.vid, // 视频id
        playauth: this.auth, // 播放凭证
        encryptType: '1', // 如果播放加密视频，则需设置encryptType=1，非加密视频无需设
        width: '100%',
        height: '500px'
      },
      function(player) {
        console.log('播放器创建成功')
      }
    )
  }
}
</script>
